<? require_once ('../../models/Cart.php'); ?>
<? require_once ('../../models/Orders.php'); ?>
<? require_once ('../../models/Accounts.php'); ?>
<? require_once ('../../models/Users.php'); ?>
<? require_once ('../../inc/functions.php'); ?>
<? RequireLogin(); ?>
<? $orderRow=Orders::Blank();

	if(isset($_POST['ShipName']))
	{
		$orderRow['ShipName']=$_POST['ShipName'];
		$orderRow['ShipAddress']=$_POST['ShipAddress'];
		$orderRow['ShipAddress2']=$_POST['ShipAddress2'];
		$orderRow['ShipCity']=$_POST['ShipCity'];
		$orderRow['ShipState']=$_POST['ShipState'];
		$orderRow['ShipZip']=$_POST['ShipZip'];
		$orderRow['ShipPhone']=$_POST['ShipPhone'];
		$orderRow['Total']=$_SESSION['grandTotal'];
		$orderRow['Tax']=$_SESSION['grandTotal']*.08;
		$orderRow['Shipping']=5;
		$orderRow['User_id']=$_SESSION['UserId'];
		
		$response=Orders::Insert($orderRow);
	}
?>
<! View -->
<!DOCTYPE html>
<html lang="en">
	<?php include('../../inc/head.php'); ?>
	<body>
		<div>
			<?php include('../../inc/nav.php'); ?>
		</div>
		
		<? if (isset($response)) { ?>
			
			<div id="content">
				<h1>Confirmation</h1>
			</div>		
			
			<div id="content">
				Name: <?=$orderRow['ShipName']?><br>
				Address: <?=$orderRow['ShipAddress']?><br>
				Address 2: <?=$orderRow['ShipAddress2']?><br>
				City: <?=$orderRow['ShipCity']?><br>
				State: <?=$orderRow['ShipState']?><br>
				Zip Code: <?=$orderRow['ShipZip']?><br>
				Phone: <?=$orderRow['ShipPhone']?><br>
				Tax: <?=$orderRow['Tax']?><br>
				Shipping: <?=$orderRow['Shipping']?><br>
				Total: <?=$orderRow['Total']?><br>
			</div>
			
			<div id="content">
			<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
				<input type="hidden" name="cmd" value="_xclick">
				<input type="hidden" name="business" value="danielayacovone@gmail.com">
				<input type="hidden" name="lc" value="US">
				<input type="hidden" name="item_name" value="Total">
				<input type="hidden" name="amount" value="<?=$_SESSION['grandTotal']?>">
				<input type="hidden" name="button_subtype" value="services">
				<input type="hidden" name="no_note" value="0">
				<input type="hidden" name="currency_code" value="USD">
				<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
				<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
				<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
			</form>

		</div>
		<? } 
		else { ?>
		
		<div id="content">
			<h1>Checkout</h1>
		</div>		
		
		<? $tax = round($_SESSION['total'] * .08, 2); ?>
		<? $shipping = 5; ?>

		<div id=content>
			<form class="form-horizontal" action="checkout.php?submitted=true" method="post">
				<p><strong>Shipping Information</strong></p>
				Name: <input type="text" name="ShipName"><br>
				Address: <input type="text" name="ShipAddress"><br>
				Address 2: <input type="text" name="ShipAddress2"><br>
				City: <input type="text" name="ShipCity"><br>
				State: <input type="text" name="ShipState"><br>
				Zip Code: <input type="text" name="ShipZip"><br>
				Phone: <input type="text" name="ShipPhone"><br>
				<p>Total: $<?=$_SESSION['total']?></p>
				<p>Tax: $<?=$tax?></p>
				<p>Shipping: $<?=$shipping?></p>
				<? $_SESSION['grandTotal'] = $_SESSION['total'] + $tax + $shipping; ?>
				<p>Grand total: <strong>$<?=$_SESSION['grandTotal']?></strong></p>
				<input type="hidden" name="User_id" value=<?=$_SESSION['UserId']?>>
				<div class="control-group">
					<div class="controls">
						<input type="submit" value="Submit" class="btn btn-primary">
					</div>
				</div>
			</form>
		</div>
		<? } ?>
		
		
		<div id="content">
			<?php include('../../inc/footer.php'); ?>
		</div>

	</body>
</html>